<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<%@ taglib prefix="memberForm" uri="http://www.tongxingzhe.cn/memberForm" %>
<!DOCTYPE html>
<html lang="zh">
<head>
<title>${project == null ? '发布' : '编辑'}项目</title>
<%@include file="../include/commonFile.jsp" %>
<link rel="stylesheet" href="${ctx}/css/common/list.css">
<link rel="stylesheet" href="${ctx}/css/common/form.css">
<link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
	<style TYPE="text/css">
		.form-tip {
			float: left;
			margin-right: 10px;
			width: calc(100% - 110px);
		}
	</style>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
	<%@include file="../include/sidebar.jsp"%>
	<!--内容-->
	<section>
		<div class="section-main">
			<!-- 正文请写在这里 -->
			<div class="add-form-content">
			<form id="myForm" class="layui-form mt20" method="post" action="${ctx}/competition/project/save.do">
				<input type="hidden" lay-verify="groupIsExpire" />
				<div class="layui-form-item">
					<label class="layui-form-label">项目名称<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<input type="text" name="title" lay-verify="required" maxlength="35" placeholder="请输入项目名称" class="layui-input form-tip" value="${project.title}" style="width: 50%">
						<div class="layui-form-mid layui-word-aux">最多35字符</div>
						<input type="hidden" name="id" value="${project.id}"/>
					</div>
				</div>
				<%--<div class="layui-form-item">
					<label class="layui-form-label">封面图<span class="f-verify-red">*</span></label>
					<div class="cover-content">
						<input type="hidden" name="picture" id="pic" lay-verify="required" value="${project.picture}" />
						<c:if test="${project == null || empty project.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
						</c:if>
						<c:if test="${project != null && not empty project.picture}">
							<span id="cover-img" class="cover-img" style="background-image:url('${project.picture}')"></span>
						</c:if>
						<a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加封面图</a>
						<div class="form-word-aux">建议尺寸：800x450</div>
					</div>
				</div>--%>
				<div class="layui-form-item">
					<label class="layui-form-label">赛事时间<span class="f-verify-red">*</span></label>
					<div class="layui-input-inline">
						<input class="layui-input" name="startTimeStr" lay-verify="startTimeStr" type="text" readonly
							value='<fmt:formatDate value="${project.startTime}" pattern="yyyy-MM-dd HH:mm" />'
						/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">赛事日程<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<jsp:include page="scheduleInclude.jsp"/>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">规则说明<span class="f-verify-red">*</span></label>
					<div class="layui-input-block">
						<textarea name="remarks" class="layui-textarea" lay-verify="remarks" placeholder="在此填写成绩规则说明，如：总排行只计算第一阶段成绩；">${project.remarks}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
						<a href="${ctx}/competition/project/list.do" class="layui-btn layui-btn-primary">取消</a>
					</div>
				</div>
			</form>
			</div>
		</div>
		<!--底部-->
		<%@include file="../include/footer.jsp" %>
		<c:set var="isExpire" value="${memberForm:isExpire(sessionScope.newCurrentUser.id, null)}"/>
	</section>
</div>
<script>

	$(function() {

        layui.use(['form', 'laydate'], function () {
            var form = layui.form, laydate = layui.laydate;

            form.verify({
                groupIsExpire: function() {
                    if ('${isExpire}' == 'true' && '${project.id}' == '') {
                        txz.openExpireDialog();
                        return false;
                    }
                    return "";
                },
                title : function(value) {
                    if (value == "") {
                        return '请填写项目名称';
                    }
                },
                // picture : function(value) {
                // 	if (value == "") {
                // 		return "请上传项目封面图";
                // 	}
                // },
                startTimeStr: function (value) {
                    if (value == "") {
                        return "请选择赛事时间";
                    }
                    // var nowDate = new Date();
                    // var stdt = new Date(value.replace("-", "/"));
                    // if (stdt < nowDate) {
                    //     return "赛事时间不得早于当前时间";
                    // }
                },
                remarks : function (value) {
                    if (value == "" || value.trim() == "") {
                        return "请填写规则说明";
                    }
                }
            });

            //监听提交
            form.on('submit', function(data) {
                var eventTime = $("[name=startTimeStr]").val();
                if (checkCost(eventTime)) {
                    submitBefore(data, submitForm);
                }
            });

            function submitForm(data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/competition/project/list.do";
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    });
                })
                return true;
            }

            //日期
            var start = {
                elem: 'input[name=startTimeStr]',
                // min: new Date().Format("yyyy-MM-dd HH:mm:ss"),
                type: 'datetime',
                format : 'yyyy-MM-dd HH:mm'
            };
            laydate.render(start);
        });
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.COMPETITION.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
	})

</script>
<c:if test="${empty project}">
	<script type="text/javascript">
		txz.initHeader({
			nav:[{
				name: '我发布的赛事项目'
			},{
				name: '发布项目',
				curr: true
			}],
			btns:[{
				name: '返回',
				icon: 'back',
				href: '${ctx}/competition/project/list.do'
			}]
		});
	</script>
</c:if>
<c:if test="${not empty project}">
	<script type="text/javascript">
		txz.initHeader({
			nav:[{
				name: '我发布的赛事项目'
			},{
				name: '编辑项目',
				curr: true
			}],
			btns:[{
				name: '返回',
				icon: 'back',
				href: '${ctx}/competition/project/list.do'
			}]
		});
	</script>
</c:if>
</body>
</html>